package com.dcdata.jt809server.head.impl;

import com.dcdata.jt809server.bean.dto.TrafficVehicleLocationDTO;
import com.dcdata.jt809server.packet.TrafficVehicleLocationPacket;
import com.dcdata.jt809server.thread.ThreadPoolFactory;
import com.dcdata.jt809server.thread.VehicleLocationThread;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;

/**
 * program: JT809Server
 * description: 车辆定位信息
 * @author DCDATA
 * @date 2020-03-16 15:08
 **/
@Slf4j
public class TrafficVehicleLocationHandler extends SimpleChannelInboundHandler<TrafficVehicleLocationPacket> {

    private static final ExecutorService EXECUTOR = ThreadPoolFactory.newSynchronousQueueExecutor(256);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, TrafficVehicleLocationPacket msg) {
        log.info("车辆定位信息：{}", msg);
        // 获取DTO对象
        TrafficVehicleLocationDTO trafficVehicleLocationDTO = new TrafficVehicleLocationDTO(msg);

        // 执行持久化
        EXECUTOR.execute(new VehicleLocationThread(trafficVehicleLocationDTO));
    }
}
